package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.controller.bean.SanHuiYiKeVo;
import net.zoneland.knowledge.model.DiYiYiTi;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 第一议题数据接口.
 */
@Mapper
public interface DiYiYiTiMapper {

    /**
     * 查询列表.
     * @param sanHuiYiKeVo 对象
     * @return 集合
     */
    @Select("<script>" +
            "SELECT ID, MEETING_DATE, LEARNING_CONTENT, MEETING_TYPE, MEETING_NAME, LEARNING_FORM, MEETING_PARTICIPANT, MEETING_LEAVE, MEETING_ATTEND, MEETING_DEPLOY,COMPANY_NAME  " +
            "FROM AITK_DI_YI_YI_TI " +
            "WHERE 1=1 " +
            " <if test='meetingName != null and meetingName != \"\" '> AND (MEETING_NAME like '%${meetingName}%' or LEARNING_CONTENT like '%${meetingName}%' ) </if>" +
            " <if test='meetingStartTime != null and meetingEndTime != null '> " +
            " AND " +
            " MEETING_DATE BETWEEN to_date('${meetingStartTime} 00:00:00', 'YYYY-MM-dd HH24:mi:ss') AND to_date('${meetingEndTime} 23:59:59', 'YYYY-MM-dd HH24:mi:ss')" +
            "</if>" +
            " <if test='publishTime != null or finishTime != null'> " +
                " AND (" +
                    " <if test='publishTime != null'> " +
                    " MEETING_DATE &lt; to_date('${publishTime} 00:00:00', 'YYYY-MM-dd HH24:mi:ss') " +
                    "</if>" +
                    " <if test='publishTime != null and finishTime != null'> " +
                    " or " +
                    "</if>" +
                    " <if test='finishTime != null'> " +
                    " MEETING_DATE &gt; to_date('${finishTime} 23:59:59', 'YYYY-MM-dd HH24:mi:ss') " +
                    "</if>" +
                    " <if test='isDiscuss'> " +
                    " or " +
                    " LEARNING_FORM NOT LIKE '%研讨%' " +
                    "</if>" +
                " )" +
            " ORDER BY MEETING_DATE DESC " +
            "</if>" +
            "</script>"
    )
    @Results({
            @Result(column="ID", property="id", jdbcType= JdbcType.VARCHAR, id=true),
            @Result(column="MEETING_DATE", property="meetingDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LEARNING_CONTENT", property="learningContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_TYPE", property="meetingType", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_NAME", property="meetingName", jdbcType=JdbcType.VARCHAR),
            @Result(column="LEARNING_FORM", property="learningForm", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_PARTICIPANT", property="meetingParticipant", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_LEAVE", property="meetingLeave", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_ATTEND", property="meetingAttend", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_DEPLOY", property="meetingDeploy", jdbcType=JdbcType.VARCHAR),
            @Result(column="COMPANY_NAME", property="companyName", jdbcType=JdbcType.VARCHAR)
    })
    List<DiYiYiTi> search(final SanHuiYiKeVo sanHuiYiKeVo);

    /**
     * 查询.
     * @param id id
     * @return 对象
     */
    @Select({
            "SELECT ID, MEETING_DATE, LEARNING_CONTENT, MEETING_TYPE, MEETING_NAME, LEARNING_FORM, MEETING_PARTICIPANT, MEETING_LEAVE, MEETING_ATTEND, MEETING_DEPLOY,COMPANY_NAME ",
            "FROM AITK_DI_YI_YI_TI ",
            "WHERE ",
            " ID = #{id, jdbcType= VARCHAR}"
    })
    @Results({
            @Result(column="ID", property="id", jdbcType= JdbcType.VARCHAR, id=true),
            @Result(column="MEETING_DATE", property="meetingDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LEARNING_CONTENT", property="learningContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_TYPE", property="meetingType", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_NAME", property="meetingName", jdbcType=JdbcType.VARCHAR),
            @Result(column="LEARNING_FORM", property="learningForm", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_PARTICIPANT", property="meetingParticipant", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_LEAVE", property="meetingLeave", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_ATTEND", property="meetingAttend", jdbcType=JdbcType.VARCHAR),
            @Result(column="MEETING_DEPLOY", property="meetingDeploy", jdbcType=JdbcType.VARCHAR),
            @Result(column="COMPANY_NAME", property="companyName", jdbcType=JdbcType.VARCHAR)
    })
    DiYiYiTi getInfoById(final String id);

}
